home *** CD-ROM | disk | FTP | other *** search
/ Hidden Truth / Hidden Truth.iso / amiga / amipeg_0.6.lha / aMiPEG06 / gray.c < prev    next >
C/C++ Source or Header  |  1996-07-03  |  4KB  |  151 lines

  1.  
  2. #include <exec/exec.h>
  3. #include <intuition/intuition.h>
  4. #include <intuition/screens.h>
  5. #include <dos/dos.h>
  6. #include <libraries/asl.h>
  7.  
  8. #include <proto/asl.h>
  9. #include <proto/exec.h>
  10. #include <proto/graphics.h>
  11. #include <proto/intuition.h>
  12. #include <proto/dos.h>
  13.  
  14. #include "video.h"
  15. #include "proto.h"
  16.  
  17. struct RastPort temprp;
  18. struct BitMap tempbm;
  19. int plane, i;
  20.  
  21. static void Quit(char *why, int failcode)
  22. {
  23.     puts(why);
  24.     exit(failcode);
  25. }
  26.  
  27. void DrawGrayImage(void *data, int x, int y)
  28. {
  29. /*    int win_x = cyber_window->Width - cyber_window->BorderLeft - cyber_window->BorderRight;
  30.     int win_y = cyber_window->Height - cyber_window->BorderTop - cyber_window->BorderBottom;
  31.  
  32.     if(win_x == x && win_y == y)
  33. */
  34.     {
  35.         WritePixelArray8(cyber_window->RPort, cyber_window->BorderLeft, cyber_window->BorderTop, cyber_window->BorderLeft + x - 1, cyber_window->BorderTop + y - 1, data, &temprp);
  36.     }
  37. }
  38.  
  39. static void output_term(void)
  40. {
  41.     close_timer();
  42.  
  43.     for(i = 0; i < plane; i++)
  44.         FreeRaster(tempbm.Planes[i], cyber_screen->Width, 1);
  45.  
  46.     if(cyber_window)
  47.         CloseWindow(cyber_window);
  48.     
  49.     if(cyber_screen)
  50.         CloseScreen(cyber_screen);
  51.  
  52.     if (IntuitionBase) CloseLibrary((struct Library *) IntuitionBase);
  53.     if (GfxBase) CloseLibrary((struct Library *) GfxBase);
  54. }
  55.  
  56. int get_modeid(void)
  57. {
  58.     struct ScreenModeRequester *scrMdReq;
  59.     int modeid = 0xffffffff;
  60.  
  61.     if(scrMdReq = AllocAslRequestTags(ASL_ScreenModeRequest,
  62.                                                                         ASLSM_MinWidth, 200,
  63.                                                                         ASLSM_MinHeight, 200,
  64.                                                                         ASLSM_MinDepth, 8,
  65.                                                                         ASLSM_MaxDepth, 8,
  66.                                                                         TAG_DONE))
  67.     {
  68.         if(AslRequestTags(scrMdReq, TAG_DONE))
  69.             modeid = scrMdReq->sm_DisplayID;
  70.  
  71.         FreeAslRequest(scrMdReq);
  72.     }
  73.  
  74.     return(modeid);
  75. }
  76.  
  77. void init_gray(void)
  78. {
  79.     atexit(output_term);
  80.  
  81.     if ((GfxBase=(struct GfxBase *) OpenLibrary("graphics.library",37))==NULL)
  82.         Quit("graphics.library is too old, <V37",25);
  83.     if ((IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",37))==NULL)
  84.         Quit("intuition.library is too old, <V37",25);
  85.  
  86. }
  87.  
  88. unsigned long InitGrayDisplay(unsigned long modeid)
  89. {
  90.     int rgb = 0;
  91.     UWORD pens[] =
  92.     {
  93.         0xf0, 0x40, 0x70, 0xff, 0x0, 0x80, 0xff, 0xc0, 0xa0, 0x0, 0xff, 0x80,
  94.         ~0
  95.     };
  96.  
  97.     init_gray();
  98.  
  99.         if((modeid != 0xffffffff) || (modeid = get_modeid()) != 0xffffffff)
  100.         {
  101.             if(cyber_screen = OpenScreenTags(NULL,
  102.                             SA_Width, STDSCREENWIDTH,
  103.                             SA_Height, STDSCREENHEIGHT,
  104.                             SA_DisplayID, modeid,
  105.                             SA_Title, (UBYTE *)"aMiPEG 0.6 by Michael Rausch and Miloslaw Smyk",
  106.                             SA_Depth, 8,
  107.                             SA_Pens, &pens,
  108.                             SA_SysFont, 1,
  109. //                            SA_BackFill, LAYERS_BACKFILL,
  110.                             TAG_DONE))
  111.             {
  112.  
  113.                 /* set palette to 0 - 255 */
  114.                 for(i = 0; i < 256; i++)
  115.                 {
  116.                     SetRGB32(&cyber_screen->ViewPort,i,rgb,rgb,rgb);
  117.                     rgb += 0x01010101;
  118.                 }
  119.  
  120.                 if(cyber_window = OpenWindowTags(NULL,
  121.                                     WA_CustomScreen, cyber_screen,
  122.                                     WA_Flags, WFLG_DEPTHGADGET | WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_SIZEBBOTTOM | WFLG_ACTIVATE,
  123.                     WA_IDCMP, CLOSEWINDOW | MOUSEBUTTONS,
  124.                     WA_InnerWidth, 160,
  125.                     WA_InnerHeight,120,
  126.                     WA_MaxWidth, ~0,
  127.                     WA_MaxHeight, ~0,
  128.                     WA_MinWidth, 60,
  129.                     WA_MinHeight, 60,
  130.                     WA_Title, "Playing MPEG animation",
  131.                     TAG_DONE))
  132.                 {
  133.                     InitRastPort(&temprp);
  134.                     InitBitMap(&tempbm, cyber_window->RPort->BitMap->Depth, cyber_screen->Width, 1);
  135.                     temprp.BitMap = &tempbm;
  136.  
  137.                     for (plane = 0; plane < tempbm.Depth; plane++)
  138.                         if(!(tempbm.Planes[plane] = AllocRaster(cyber_screen->Width, 1)))
  139.                             break;
  140.  
  141.                     if(plane != tempbm.Depth)
  142.                         modeid = 0xffffffff;
  143.  
  144.                     return(modeid);
  145.                 }
  146.             }
  147.         }
  148.  
  149.     Quit("aMiPEG: unable to open screen/window...", 25);
  150. }
  151.